import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";
import http from "../plugins/http-base.js";
// import { Message } from "element-ui";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    loginInfo: {
      username: "",
      userid: "",
      token: null
    },
    /**
     * @description 头部
     */
    showTopTool: true,
    /**
     * @description 全局加载
     */
    isTableLoading: {
      status: false,
      msg: "",
      bg: ""
    },
    /**
     * @description 测试
     */
    axiosAction: ""
  },
  mutations: {
    /**
     * @description commit 基础方法
     * @param {*} state 仓库
     * @param {*} param1 传入要变更的key以及val
     */
    change(state, { key, val }) {
      state[key] = val;
      // console.log("mutations", key, val);
    },
    // topToolToggle(state) {
    //   state.showTopTool = !state.showTopTool;
    // },
    /**
     *
     * @param { Object } state 状态仓库
     * @param { Object }  config 加载的配置
     */
    loading(state, config) {
      state.isTableLoading = config;
    }
  },
  actions: {
    change({ commit, state }, arg) {
      commit("change", arg);
      console.log("actions", arg, state.axiosData);
    },
    async login({ commit }) {
      // Message.error("能用了！！！");
      let { data } = await http({ url: "/local/hello" });

      commit("change", {
        key: "axiosAction",
        val: data.name || data
      });
    }
  },
  plugins: [createPersistedState()]
});

Vue.prototype.$store = store;
export default store;
